package com.atguigu.crowd.mvc.handler;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.atguigu.crowd.entity.Quyuejiaophoto0;
import com.atguigu.crowd.service.api.QuyuejiaoPhotoService;
import com.atguigu.crowd.util.ResultEntity;

@Controller
public class PictureHandler {
	
	@Autowired
	QuyuejiaoPhotoService quyuejiaoPhotoService;
	
	@RequestMapping("Picture/pler.ht")
	public String Pic(@RequestParam String index) {
		
		//return "forward:/img/carousel-1.jpg";
		//提高性能，用重定向
		return "redirect:/img/carousel-"+index+".jpg";
	}
	@ResponseBody
	@RequestMapping("test/quyuejiao2.ht")
	public List<Quyuejiaophoto0> testQuyuejiao2(@Param("name") String name) {
		
		List<Quyuejiaophoto0> quyuejiaoPhotoList= quyuejiaoPhotoService.getAll();
		System.out.println("--------name:-----------"+name);
		System.out.println(quyuejiaoPhotoList);
		
		//返回的是json数据 ,因为我们加了 @ResponseBody
		return quyuejiaoPhotoList;
	}
	/**
	 * 统一json格式模式
	 * @param name
	 * @return
	 */
	@ResponseBody
	@RequestMapping("test/quyuejiao1-AddFormat.ht")
	public ResultEntity<List<Quyuejiaophoto0>> testQuyuejiao3(@Param("name") String name) {
		
		List<Quyuejiaophoto0> quyuejiaoPhotoList= quyuejiaoPhotoService.getAll();
		System.out.println("AddFormat--------name:-----------"+name);
		System.out.println(quyuejiaoPhotoList);
		
		return ResultEntity.successWithData(quyuejiaoPhotoList);
	}

}
